package lp.polimi.treefinder.utils;

import java.io.Serializable;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Structure containing name and picture of a leaf which is in the final ranking.
 * It is serializable, as it's sent to the client through socket.
 */
public class RankElement implements Serializable, Parcelable {

	private static final long serialVersionUID = -1190287730504427606L;
	private byte[] photo;
	private String name;
	public static final Creator<RankElement> CREATOR = new Parcelable.Creator<RankElement>() {

		@Override
		public RankElement createFromParcel(Parcel in) {
			return new RankElement(in);
		}

		@Override
		public RankElement[] newArray(int size) {
			// TODO Auto-generated method stub
			return new RankElement[size];
		}

	};


	public RankElement(byte[] photo, String name) {
		super();
		this.photo = photo;
		this.name = name;
	}


	public RankElement (Parcel in) {

		name=in.readString();
		in.readByteArray(photo);

	}

	public byte[] getPhoto() {
		return photo;
	}

	public void setPhoto(byte[] photo) {
		this.photo = photo;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return getName();
	}




	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(name);
		dest.writeByteArray(photo);
	}

}
